#
# File: Makefile del frammento 2
#

CC=gcc
CFLAGS=-Wall -pedantic

SUBJECT1= "lcschat: Consegna frammento 1"
SUBJECT2= "lcschat: Consegna frammento 2"

.PHONY: all test1 consegna1  test2 consegna2 clean cleanall 

all: server client testclient

####################(inizio sezione **1**)#####################################
server:  server.o lcshash.o
	$(CC) $(CFLAGS) server.o lcshash.o -L./lib -lpthread -lcom -o server


server.o: server.c lcscom.h lcshash.h


test-frag1: test-frag1.o lcshash.o 
test-frag1.o: lcshash.h

lcshash.o: lcshash.c lcshash.h

##########################(inizio sezione **2**)#############################

#effettua il test del primo frammento
test1: test-frag1
	cp ./test1/lcshash.dat  ./.lcshash.dat
	cp ./test1/lcshash2.dat ./.lcshash2.dat
	chmod 644 ./.lcshash*
	-rm -f ./.mtrace.log
	@echo MALLOC_TRACE=$(MALLOC_TRACE)
	./test-frag1 1>./output 2>./error
	diff ./output ./test1/output.check
	mtrace ./test-frag1 ./.mtrace.log
	@echo -e "\a\n*** TEST SUPERATO! ***\n"

#effettua il test del primo frammento e la consegna
consegna1:
	make test1
	./gruppo-check.pl < gruppo.txt
	tar -cvf $(USER)-f1.tar ./gruppo.txt ./lcshash.c
	mpack -s $(SUBJECT1) ./$(USER)-f1.tar  susanna@di.unipi.it
	@echo -e "\a\n*** PROGETTO CONSEGNATO! ***\n"

#effettua il test del secondo frammento 
test2: server
	-killall server
	-killall client
	-killall testclient
	cp bin/client .
	cp bin/testclient .
	chmod 755 client testclient
	wait
	@echo Preparing test environment...
	cp test2/*.test .
	cp test2/*.check .
	chmod 755 *.test 
	chmod 644 *.check
	@echo Starting server process ...
	./server pippo 1>./.serverout 2>./.servererror
	@echo Using checkAll script to make first test ...
	./checkAll . 2>outtest
	more outtest
	diff ./outtest ./test2/outtest.check
	@echo Testing parallelism ...
	./test-frag2
	./checktestfrag2out
	wait
	@echo -e "\a\n*** TEST SUPERATO (2) ! ***\n"


#effettua il test del secondo frammento e la consegna
consegna2:
	make test1
	make test2
	./gruppo-check.pl < gruppo.txt
	tar -cvf $(USER)-f2.tar ./gruppo.txt ./*.h ./*.c ./checkAll ./Makefile
	mpack -s $(SUBJECT2) ./$(USER)-f2.tar  susanna@di.unipi.it
	@echo -e "\a\n*** PROGETTO CONSEGNATO (2) !***\n"

###########################################################################

clean:
	-rm -f *~ core 

cleanall:	
	-rm -f *.o *~ core .mtrace.log 



